package org.pms.servlet.administrators;

import org.pms.dao.AdministratorsDao;
import org.pms.dao.impl.AdministratorsDaoImpl;
import org.pms.entity.Administrators;
import org.pms.servlet.BaseServlet;
import org.pms.vo.ResponseData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 管理员登录
 * @Date 2022-12-12
 * @Author 祝世栩
 */
@WebServlet("/administrators/SigninServlet")
public class SigninServlet extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取浏览器传递过来的数据
        String AdministratorsNumber = req.getParameter("account");
        String AdministratorsPwd = req.getParameter("password");

        // 业务处理 - 数据库（查询、持久化数据） - DAO
        AdministratorsDao administratorsDao = new AdministratorsDaoImpl();
        Administrators administrators = administratorsDao.AdministratorsSelectNumberPwd(AdministratorsNumber,AdministratorsPwd);

        ResponseData responseData =  successJson(administrators);

        print(resp,responseData);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
